package com.xxj.puzzlesheep.core;


import com.xxj.puzzlesheep.util.LGraphicsUtils;

import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;

/**
 * 
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email ceponline@yahoo.com.cn
 * @version 0.1.0
 */
public abstract class LScreen implements ILScreen {

	private ILHandler handler;

	private int width, height;

	public LScreen() {
		this.handler = LSystem.getSystemHandler();
		this.width = handler.getWidth();
		this.height = handler.getHeight();
	}

	public LImage getLAImage(String fileName) {
		return LGraphicsUtils.loadLAImage(fileName);
	}

	public synchronized void createUI(LGraphics g) {
		draw(g);
	}

	public abstract void draw(LGraphics g);

	public synchronized void runTimer(LTimerContext timer) {
		alter(timer);
	}

	public void alter(LTimerContext timer){
		
	}

	public void setScreen(ILScreen screen) {
		this.handler.setScreen(screen);
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}
	

	
	public boolean onKey(int keyCode, KeyEvent e) {
		switch (e.getAction()) {
		case KeyEvent.ACTION_DOWN:
			return onKeyDown(keyCode,e);
		case KeyEvent.ACTION_UP:
			return onKeyUp(keyCode,e);
		}
		return true;
	}

	public boolean onKey(View v, int keyCode, KeyEvent event) {
		return onKey(keyCode, event);
	}

	public void onFocusChange(boolean hasFocus) {

	}

	public void onFocusChange(View v, boolean hasFocus) {
		onFocusChange(hasFocus);
	}

	public boolean onLongClick() {
		return false;
	}

	public boolean onLongClick(View v) {
		return onLongClick();
	}

	public void onClick() {

	}

	public void onClick(View v) {
		onClick();
	}

	public void onCreateContextMenu(ContextMenu menu, ContextMenuInfo menuInfo) {

	}

	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		onCreateContextMenu(menu, menuInfo);
	}

	public boolean onTouch(MotionEvent e) {
		switch (e.getAction()) {
		case MotionEvent.ACTION_DOWN:
			return onTouchDown(e);
		case MotionEvent.ACTION_UP:
			return onTouchUp(e);
		case MotionEvent.ACTION_MOVE:
			return onTouchMove(e);
		}
		return true;
	}

	public boolean onTouch(View v, MotionEvent event) {
		return onTouch(event);
	}

}
